package com.lib.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class ThreadPoolUtils {
    private static final ScheduledExecutorService mScheduledExecutorService;

    static {// 自定义线程工厂
        ThreadFactory threadFactory = new ThreadFactory() {
            private final AtomicInteger threadNumber = new AtomicInteger(1);

            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r, "ThreadPoolUtils-" + threadNumber.getAndIncrement());
                thread.setDaemon(false);
                return thread;
            }
        };
        mScheduledExecutorService = new ScheduledThreadPoolExecutor(3, threadFactory);
    }

    private ThreadPoolUtils() {
    }

    public static ScheduledExecutorService get() {
        return mScheduledExecutorService;
    }
}